package atomicLock

import (
	"runtime"
	"sync"
	"sync/atomic"
)

type lock uint32

func (l *lock) Lock() {
	for !atomic.CompareAndSwapUint32((*uint32)(l), 0, 1) {
		runtime.Gosched()
	}
}

func (l *lock) Unlock() {
	atomic.StoreUint32((*uint32)(l), 0)
}

func NewLock() sync.Locker {
	return new(lock)
}
